<template>
  <div class="callback">
    <!--加载中...-->
  </div>
</template>
<script>
import qs from 'querystring';
import cookie from '../lib/cookie';
import service from '../service/callback';

export default {
  data() {
    return {
      queryObj: JSON.parse(cookie('queryObj')),
    };
  },
  /* eslint-disable */
  mounted() {
    const appId = window.location.href.split('?')[1].split('=')[1];
    const { search } = window.location;
    const qsData = qs.parse(search.substr(1));
    // get queryString from url
    const { code } = qsData;
    cookie('code', code)
    if(this.queryObj.wxScope == 1) {
      service.getUserInfo({
        id: this.queryObj.groupCollectionId,
        code,
        appId: this.queryObj.appId?this.queryObj.appId:appId,
      }).then((data) => {
        if(data == 'success') {
          window.sessionStorage.setItem("isAuth",'1');
          this.$router.push({
            name: 'join',
            query: this.queryObj,
          });
        }
      }, (e) => {
        alert(e);
      });
    } else {
      service.getOpenId({
        code,
        appId: this.queryObj.appId?this.queryObj.appId:appId,
      }).then((data) => {
        if(data == 'success') {
          window.sessionStorage.setItem("isAuth",'1');
          this.$router.push({
            name: 'join',
            query: this.queryObj,
          });
        }
      }, (e) => {
        alert(e);
      });
    }
  },
};
</script>
<style lang="less" scoped>

</style>
